package com.easy.easylibdemo.ui.mulitlist.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.easy.easylibdemo.R;
import com.easy.easylibdemo.ui.mulitlist.model.TitleBean;

import java.util.List;

/**
 * 作　　者: guyj
 * 修改日期: 2017/3/27
 * 描　　述:
 * 备　　注:
 */
public class MultiAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    List<Object> beans;
    Context con;
    public MultiAdapter(Context con,List<Object> beans) {
        this.beans = beans;
        this.con=con;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;
        if (viewType==2){
            view= LayoutInflater.from(con).inflate(R.layout.item_title,parent,false);
            return new TitleHolder(view);
        }else{
            view= LayoutInflater.from(con).inflate(R.layout.item_grid,parent,false);
            return new ContentHolder(view);
        }
    }
    @Override
    public int getItemViewType(int position) {
        if (beans.get(position) instanceof TitleBean){
            return 2;
        }else {
            return 1;
        }
    }
    class TitleHolder extends RecyclerView.ViewHolder{
        public TitleHolder(View itemView) {
            super(itemView);
        }
    }
    class ContentHolder extends RecyclerView.ViewHolder{
        public ContentHolder(View itemView) {
            super(itemView);
        }
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    }
    @Override
    public int getItemCount() {
        return beans.size();
    }
    public void setData(List<Object> beans){
        this.beans=beans;
    }
}
